package cate.game.train.kitchenware.msg;

import cate.common.annotation.OperationSetter;
import cate.common.table.d.GDOperation;
import cate.common.util.GameResult;
import cate.game.GameBody;
import cate.game.client.ClientContext;
import cate.game.client.msg.ClientMsg;
import cate.game.client.msg.MsgConfig;
import cate.game.client.msg.MsgInput;
import cate.game.client.msg.id.MsgIdBTrain;
import cate.game.role.Role;
import cate.game.role.bag.hero.Hero;
import cate.game.role.bag.kitchenware.Kitchenware;
import easy.java.dev.note.NoteField;

@ClientMsg(title = "英雄穿厨具の 请求")
@OperationSetter(GDOperation.KITCHENWARE_ON)
public class KitchenwareOnReq implements MsgInput {
    @NoteField(value = "英雄ID", detail = "要给哪一个英雄穿装备")
    public String heroUid;

    @NoteField(value = "位置")
    public byte pos;

    @NoteField(value = "厨具唯一id")
    public String kitchenwareUid;

    @Override
    public void execute(GameBody game, ClientContext cc) {
        Role role = cc.getRole();
        Hero hero = role.getBag().hero.getItem(heroUid);
        if (hero == null) {
            game.notice.message(role, "英雄不存在");
            return;
        }
        Kitchenware kitchenware = role.getBag().kitchenware.getItem(kitchenwareUid);
        if(kitchenware == null){
            game.notice.message(role, "厨具不存在");
            return;
        }
        GameResult<Byte> r = hero.onKitchenware(role.toPlayBuildContext(), kitchenware, pos);
        if (!r.ok()) {
            game.notice.message(role, r.message);
            return;
        }
        cc.sendNow(new KitchenwareOnResp(heroUid, pos, kitchenware));
    }

    @Override
    public MsgConfig conf() {
        return MsgIdBTrain.KITCHENWARE_ON_REQ;
    }
}
